package com.yisen.dasan.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yisen.dasan.dao.AnswerMapper;
import com.yisen.dasan.pojo.*;
import com.yisen.dasan.service.AnswerService;
import com.yisen.dasan.util.TimeUtils;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author yu258234
 * @Description: 答案表相关实现
 */
@Service
public class AnswerServiceImpl implements AnswerService {
    @Autowired
    AnswerMapper answerMapper;

    /**
     * 添加答案表的封装
     * @param jsonObject
     * @return
     */
    @Override
    public boolean addAnswer(JSONObject jsonObject) {
        if(jsonObject==null){
            return false;
        }
        int indexId=addResultSign(jsonObject);
        JSONArray form_text=jsonObject.getJSONArray("form_text");
        for(int i=0;i<form_text.size();i++){
            JSONObject obj=form_text.getJSONObject(i);
            addAnswerType(obj.getString("option"),indexId,obj.getString("type"));
        }
        return true;
    }

    /**
     * 查询答案表的封装
     * @param formId
     * @return
     */
    @Override
    public JSONObject getAnswer(int formId,int pageNum){
        JSONObject result = new JSONObject();// 最后返回结果

        JSONObject head = new JSONObject();// 封装head属性

        List<Map> formItem = answerMapper.getFormItem(formId);// 取得表单项所需信息

        for (Map map : formItem) {// head属性封装完成
            head.put("a"+map.get("item_num"), map.get("title"));
        }

        PageHelper.startPage(pageNum, 40);// 查询要查询的所有填写答案标记
        List<Map> resultSign = answerMapper.getResultSign(formId);// 取得要查询的答案标记
        PageInfo<Map> resultPage = new PageInfo<>(resultSign);
        LinkedHashMap<String,JSONObject> hashMap = new LinkedHashMap<>();// 存每一条数据
        List<String> signs = new ArrayList<>();
        for (Map map : resultSign) {// 拿到所有要查询的标记
            String index = map.get("id").toString();
            signs.add(index);
            JSONObject jsonObject = new JSONObject();
            hashMap.put(index, jsonObject);
        }

        for (Map map : formItem) {// 查询该表单所有要查询表单项答案
            if (signs.size()==0){// 没有要查询的答案，所以该循环无意义
                break;
            }
            String key = "a"+map.get("item_num");
            if (map.get("type").toString().equals("radio")){// 单选表的答案赋值
                List<Map> list = answerMapper.getAnswerRadio((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("multiple")){// 多选表的答案赋值
                List<Map> list = answerMapper.getAnswerMultiple((Integer) map.get("id"), signs);
                for (Map m : list) {
                    JSONObject jsonObject = hashMap.get(m.get("index_id").toString());
                    if (jsonObject.containsKey(key))
                        jsonObject.put(key,jsonObject.getString(key)+","+m.get("text"));
                    else
                        jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("completion")){// 填空表的答案赋值
                List<Map> list = answerMapper.getAnswerCompletion((Integer) map.get("id"), signs);
                for (Map m : list) {
                    JSONObject jsonObject = hashMap.get(m.get("index_id").toString());
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("field")){// 简答表的答案赋值
                List<Map> list = answerMapper.getAnswerField((Integer) map.get("id"), signs);
                for (Map m : list) {
                    JSONObject jsonObject = hashMap.get(m.get("index_id").toString());
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("number")){// 数字表的答案赋值
                List<Map> list = answerMapper.getAnswerNumber((Integer) map.get("id"), signs);
                for (Map m : list) {
                    JSONObject jsonObject = hashMap.get(m.get("index_id").toString());
                    String string = new BigDecimal((double) m.get("number")).toPlainString();
                    jsonObject.put(key,string);
                }
            }else if (map.get("type").toString().equals("imgSingle")){// 图片单选表的答案赋值
                List<Map> list = answerMapper.getAnswerImageradio((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("imageurl"));
                }
            }else if (map.get("type").toString().equals("select")){
                List<Map> list = answerMapper.getAnswerSelect((Integer) map.get("id"),signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("name")){
                List<Map> list = answerMapper.getAnswerName((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("gender")){
                List<Map> list = answerMapper.getAnswerGender((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("education")){
                List<Map> list = answerMapper.getAnswerEducation((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("age")){
                List<Map> list = answerMapper.getAnswerAge((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("iphone")){
                List<Map> list = answerMapper.getAnswerIphone((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("email")){
                List<Map> list = answerMapper.getAnswerEmail((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("mobile")){
                List<Map> list = answerMapper.getAnswerMobile((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("birthday")){
                List<Map> list = answerMapper.getAnswerBirthday((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }
        }
        result.put("head", head);// 封装head
        List<JSONObject> text = new ArrayList<>();// 封装 text
        for (String key : hashMap.keySet()) {
            text.add(hashMap.get(key));
        }
        result.put("text", text);
        JSONObject page = new JSONObject();// 封装page
        page.put("pageNum", resultPage.getPageNum());
        page.put("size", resultPage.getSize());
        page.put("pages", resultPage.getPages());
        page.put("total", resultPage.getTotal());
        result.put("page", page);
        return result;
    }

    @Override
    public void getAllAnswer(int formId, HttpServletResponse response) throws IOException {
        Map<String,Object> head = new HashMap<String,Object>();// 封装head属性

        List<Map> formItem = answerMapper.getFormItem(formId);// 取得表单项所需信息

        for (Map map : formItem) {// head属性封装完成
            head.put("a"+map.get("item_num"), map.get("title"));
        }
        List<Map> resultSign = answerMapper.getResultSign(formId);// 取得要查询的答案标记
        LinkedHashMap<String,JSONObject> hashMap = new LinkedHashMap<>();// 存每一条数据
        List<String> signs = new ArrayList<>();
        for (Map map : resultSign) {// 拿到所有要查询的标记
            String index = map.get("id").toString();
            signs.add(index);
            JSONObject jsonObject = new JSONObject();
            hashMap.put(index, jsonObject);
        }

        for (Map map : formItem) {// 查询该表单所有要查询表单项答案
            if (signs.size()==0){// 没有要查询的答案，所以该循环无意义
                break;
            }
            String key = "a"+map.get("item_num");
            if (map.get("type").toString().equals("radio")){// 单选表的答案赋值
                List<Map> list = answerMapper.getAnswerRadio((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("multiple")){// 多选表的答案赋值
                List<Map> list = answerMapper.getAnswerMultiple((Integer) map.get("id"), signs);
                for (Map m : list) {
                    JSONObject jsonObject = hashMap.get(m.get("index_id").toString());
                    if (jsonObject.containsKey(key))
                        jsonObject.put(key,jsonObject.getString(key)+","+m.get("text"));
                    else
                        jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("completion")){// 填空表的答案赋值
                List<Map> list = answerMapper.getAnswerCompletion((Integer) map.get("id"), signs);
                for (Map m : list) {
                    JSONObject jsonObject = hashMap.get(m.get("index_id").toString());
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("field")){// 简答表的答案赋值
                List<Map> list = answerMapper.getAnswerField((Integer) map.get("id"), signs);
                for (Map m : list) {
                    JSONObject jsonObject = hashMap.get(m.get("index_id").toString());
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("number")){// 数字表的答案赋值
                List<Map> list = answerMapper.getAnswerNumber((Integer) map.get("id"), signs);
                for (Map m : list) {
                    JSONObject jsonObject = hashMap.get(m.get("index_id").toString());
                    String string = new BigDecimal((double) m.get("number")).toPlainString();
                    jsonObject.put(key,string);
                }
            }else if (map.get("type").toString().equals("imgSingle")){// 图片单选表的答案赋值
                List<Map> list = answerMapper.getAnswerImageradio((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("imageurl"));
                }
            }else if (map.get("type").toString().equals("select")){//下拉
                List<Map> list = answerMapper.getAnswerSelect((Integer) map.get("id"), signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("name")){
                List<Map> list = answerMapper.getAnswerName((Integer) map.get("id"),signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("gender")){
                List<Map> list = answerMapper.getAnswerGender((Integer) map.get("id"),signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("education")){
                List<Map> list = answerMapper.getAnswerEducation((Integer) map.get("id"),signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("age")){
                List<Map> list = answerMapper.getAnswerAge((Integer) map.get("id"),signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("iphone")){
                List<Map> list = answerMapper.getAnswerIphone((Integer) map.get("id"),signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("email")){
                List<Map> list = answerMapper.getAnswerEmail((Integer) map.get("id"),signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("mobile")){
                List<Map> list = answerMapper.getAnswerMobile((Integer) map.get("id"),signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }else if (map.get("type").toString().equals("birthday")){
                List<Map> list = answerMapper.getAnswerBirthday((Integer) map.get("id"),signs);
                for (Map m : list) {
                    String index_id = m.get("index_id").toString();
                    JSONObject jsonObject = hashMap.get(index_id);
                    jsonObject.put(key,m.get("text"));
                }
            }
        }
        List<JSONObject> text = new ArrayList<>();// 封装 text
        for (String key : hashMap.keySet()) {
            text.add(hashMap.get(key));
        }
        // excel 进行封装
        //声明一个工作簿
        HSSFWorkbook workbook = new HSSFWorkbook();
        //生成一个表格，设置表格名称为"学生表"
        HSSFSheet sheet = workbook.createSheet("答案表");
        //设置表格列宽度为10个字节
        sheet.setDefaultColumnWidth(10);
        //创建第一行表头
        HSSFRow headrow = sheet.createRow(0);
        //遍历增加标题行
        for (String key : head.keySet()) {
            //创建一个单元格
            HSSFCell cell = headrow.createCell(Integer.parseInt(key.substring(1)));
            //创建一个内容对象
            HSSFRichTextString text1 = new HSSFRichTextString(head.get(key).toString());
            //将内容对象的文字内容写入到单元格中
            cell.setCellValue(text1);
        }
        //遍历增加内容
        for (int i = 1; i <= text.size(); i++) {
            //创建行对象
            HSSFRow row = sheet.createRow(i);
            //遍历增加每行答案显示
            for (String key : head.keySet()) {
                //创建一个单元格
                HSSFCell cell = row.createCell(Integer.parseInt(key.substring(1)));
                // 内容文本
                Optional<Object> op = Optional.of(
                        Optional.ofNullable(text.get(i-1).get(key)).orElse(new String(""))
                );
                //创建一个内容对象
                HSSFRichTextString text1 = new HSSFRichTextString(op.get().toString());
                //将内容对象的文字内容写入到单元格中
                cell.setCellValue(text1);
            }
        }
        //准备将Excel的输出流通过response输出到页面下载
        //八进制输出流
        response.setContentType("application/octet-stream");

        //这后面可以设置导出Excel的名称，此例中名为student.xls
        response.setHeader("Content-disposition", "attachment;filename="+System.currentTimeMillis()+".xls");

        //刷新缓冲
        response.flushBuffer();

        //workbook将Excel写入到response的输出流中，供页面下载
        workbook.write(response.getOutputStream());
    }

    /**
     * 插入答案标记表，并返回标记id
     * @param jsonObject
     * @return
     */
    private int addResultSign(JSONObject jsonObject){
        AnswerResultSign answerResultSign = new AnswerResultSign();
        answerResultSign.setFormId(jsonObject.getInteger("form_id"));
        answerResultSign.setIndex(jsonObject.getString("index"));// TODO 填写答案ip地址记录
        answerResultSign.setDate(TimeUtils.getSecondTimestampTwo());
        answerResultSign.setCityName(jsonObject.getString("cityName"));
        answerResultSign.setTime(jsonObject.getInteger("time"));
        System.out.println(answerResultSign);
        answerMapper.addAnswerResultSign(answerResultSign);
        return answerResultSign.getId();
    }

    /**
     * 整合数据并且插入结果答案表（对应不同属性）
     * @param str
     * @param indexId
     * @param type
     */
    private void addAnswerType(String str,int indexId,String type){
        if(type.equals("completion")){
            JSONObject jsonObject = JSONObject.parseObject(str);
            AnswerCompletion answerCompletion = new AnswerCompletion();
            answerCompletion.setItemId(jsonObject.getInteger("item_id"));
            answerCompletion.setIndexId(indexId);
            answerCompletion.setText(jsonObject.getString("text"));
            answerMapper.addAnswerCompletion(answerCompletion);
        }else if(type.equals("radio")){
            JSONObject jsonObject = JSONObject.parseObject(str);
            AnswerRadio answerRadio = new AnswerRadio();
            answerRadio.setItemId(jsonObject.getInteger("item_id"));
            answerRadio.setOptionId(jsonObject.getInteger("option_id")-1);
            answerRadio.setIndexId(indexId);
            answerRadio.setText(jsonObject.getString("text"));
            answerMapper.addAnswerRadio(answerRadio);
        }else if (type.equals("field")){
            JSONObject jsonObject = JSONObject.parseObject(str);
            AnswerField answerField = new AnswerField();
            answerField.setItemId(jsonObject.getInteger("item_id"));
            answerField.setIndexId(indexId);
            answerField.setText(jsonObject.getString("text"));
            answerMapper.addAnswerField(answerField);
        }else if (type.equals("number")){
            JSONObject jsonObject = JSONObject.parseObject(str);
            AnswerNumber answerNumber = new AnswerNumber();
            answerNumber.setItemId(jsonObject.getInteger("item_id"));
            answerNumber.setIndexId(indexId);
            answerNumber.setNumber(jsonObject.getDouble("number"));
            answerMapper.addAnswerNumber(answerNumber);
        }else if (type.equals("multiple")){
            JSONArray array=JSONArray.parseArray(str);
            ArrayList<AnswerMultiple> list = new ArrayList<>();
            for (int i=0;i<array.size();i++){
                AnswerMultiple answerMultiple = new AnswerMultiple();
                JSONObject jsonObject=array.getJSONObject(i);
                answerMultiple.setItemId(jsonObject.getInteger("item_id"));
                answerMultiple.setOptionId(jsonObject.getInteger("option_id"));
                answerMultiple.setIndexId(indexId);
                answerMultiple.setText(jsonObject.getString("text"));
                list.add(answerMultiple);
            }
            answerMapper.addAnswerMultiple(list);
        }else if (type.equals("imgSingle")){
            JSONObject jsonObject=JSONObject.parseObject(str);
            AnswerImgRadio answerImgRadio = new AnswerImgRadio();
            answerImgRadio.setItemId(jsonObject.getInteger("item_id"));
            answerImgRadio.setOptionId(jsonObject.getInteger("option_id"));
            answerImgRadio.setIndexId(indexId);
            System.out.println(answerImgRadio);
            answerMapper.addAnswerImgRadio(answerImgRadio);
        }else if (type.equals("select")){
            JSONObject jsonObject=JSONObject.parseObject(str);
            AnswerSelect answerSelect=new AnswerSelect();
            answerSelect.setItemId(jsonObject.getInteger("item_id"));
            answerSelect.setOptionId(jsonObject.getInteger("option_id")-1);
            answerSelect.setIndexId(indexId);
            answerMapper.addAnswerSelect(answerSelect);
        }else if (type.equals("name")){
            JSONObject jsonObject=JSONObject.parseObject(str);
            AnswerName answerName = new AnswerName();
            answerName.setItemId(jsonObject.getInteger("item_id"));
            answerName.setIndexId(indexId);
            answerName.setText(jsonObject.getString("text"));
            answerMapper.addAnswerName(answerName);
        }else if (type.equals("gender")){
            JSONObject jsonObject = JSONObject.parseObject(str);
            Map map=(Map) jsonObject;
            map.put("indexId",indexId);
            map.put("itemId",jsonObject.getInteger("item_id"));
            map.put("optionId",jsonObject.getInteger("option_id")-1);
            answerMapper.addAnswerGender(map);
        }else if (type.equals("education")){
            JSONObject jsonObject=JSONObject.parseObject(str);
            Map map=(Map) jsonObject;
            map.put("indexId",indexId);
            map.put("itemId",jsonObject.getInteger("item_id"));
            map.put("optionId",jsonObject.getInteger("option_id")-1);
            answerMapper.addAnswerEducation(map);
        }else if (type.equals("age")){
            JSONObject jsonObject=JSONObject.parseObject(str);
            Map map=(Map) jsonObject;
            map.put("indexId",indexId);
            map.put("itemId",jsonObject.getInteger("item_id"));
            map.put("optionId",jsonObject.getInteger("option_id")-1);
            answerMapper.addAnswerAge(map);
        }else if (type.equals("iphone")){
            JSONObject jsonObject=JSONObject.parseObject(str);
            Map map=(Map) jsonObject;
            map.put("indexId",indexId);
            map.put("itemId",jsonObject.getInteger("item_id"));
            //map.put("optionId",jsonObject.getInteger("option_id"));
            answerMapper.addAnswerIphone(map);
        }else if (type.equals("email")){
            JSONObject jsonObject=JSONObject.parseObject(str);
            Map map=(Map) jsonObject;
            map.put("indexId",indexId);
            map.put("itemId",jsonObject.getInteger("item_id"));
            //map.put("optionId",jsonObject.getInteger("option_id"));
            answerMapper.addAnswerEmail(map);
        }else if (type.equals("mobile")){
            JSONObject jsonObject=JSONObject.parseObject(str);
            Map map=(Map) jsonObject;
            map.put("indexId",indexId);
            map.put("itemId",jsonObject.getInteger("item_id"));
            //map.put("optionId",jsonObject.getInteger("option_id"));
            answerMapper.addAnswerMobile(map);
        }else if (type.equals("birthday")){
            JSONObject jsonObject=JSONObject.parseObject(str);
            Map map=(Map) jsonObject;
            map.put("indexId",indexId);
            map.put("itemId",jsonObject.getInteger("item_id"));
            String text= String.valueOf(jsonObject.getTimestamp("text"));
            String[] t1=text.split(" ");
            map.put("text",t1[0]);
            answerMapper.addAnswerBirthday(map);
        }
    }

    /**
     * 整合查询到的答案表数据
     * @param formId
     * @return
     */
//    public List<SendAnswer> dealAnswer(int formId){
//        List<SendAnswer> list=new ArrayList<>();
//        List<AnswerResultSign> answerResultSign=answerMapper.getAnswerResultSign(formId);
//        for(int i=0;i<answerResultSign.size();i++){
//            //System.out.println(answerResultSign.get(i));
//            AnswerResultSign resultSign=answerResultSign.get(i);
//            SendAnswer sendAnswer=new SendAnswer();
//            sendAnswer.setData(resultSign.getDate());
//            sendAnswer.setIndex(resultSign.getIndex());
//            String flag=resultSign.getType();
//            if (flag.equals("radio")){
//                HashMap a=(HashMap)resultSign.getOption().get(0);
//                int id= (int) a.get("id");
//                AnswerDao answerDao=answerMapper.getRadio(id);
//                sendAnswer.setTitle(answerDao.getTitle());
//                sendAnswer.setContent(answerDao.getContent()+" "+answerDao.getAdditional());
//                System.out.println("RADIO:"+answerDao);
//            }else if(flag.equals("multiple")){
//                String opt="";
//                for (int j=0;j<resultSign.getOption().size();j++){
//                    HashMap a=(HashMap)resultSign.getOption().get(j);
//                    int id=(int)a.get("id");
//                    AnswerDao answerDao=answerMapper.getMultiple(id);
//                    sendAnswer.setTitle(answerDao.getTitle());
//                    opt=opt+j+answerDao.getContent()+" "+answerDao.getAdditional()+" ";
//                    System.out.println("MULTIPLE:"+answerDao);
//                }
//                sendAnswer.setContent(opt);
//            }else if(flag.equals("imgSingle")){
//                HashMap a=(HashMap)resultSign.getOption().get(0);
//                int id=(int)a.get("id");
//                AnswerDao answerDao=answerMapper.getImgRadio(id);
//                sendAnswer.setTitle(answerDao.getTitle());
//                sendAnswer.setContent(answerDao.getContent());
//                System.out.println("IMG:"+answerDao);
//            }else if(flag.equals("field")){
//                HashMap a=(HashMap)resultSign.getOption().get(0);
//                int id=(int)a.get("id");
//                AnswerDao answerDao=answerMapper.getField(id);
//                sendAnswer.setTitle(answerDao.getTitle());
//                sendAnswer.setContent(answerDao.getContent());
//                System.out.println("FIELD:"+answerDao);
//            }else if(flag.equals("completion")){
//                HashMap a=(HashMap)resultSign.getOption().get(0);
//                int id=(int)a.get("id");
//                AnswerDao answerDao=answerMapper.getCompletion(id);
//                sendAnswer.setTitle(answerDao.getTitle());
//                sendAnswer.setContent(answerDao.getContent());
//                System.out.println("COMPLETION:"+answerDao);
//            }else if(flag.equals("number")){
//                HashMap a=(HashMap)resultSign.getOption().get(0);
//                int id=(int)a.get("id");
//                AnswerDao answerDao=answerMapper.getNumber(id);
//                sendAnswer.setTitle(answerDao.getTitle());
//                sendAnswer.setContent(answerDao.getContent());
//                System.out.println("NUMBER:"+answerDao);
//            }
//            list.add(sendAnswer);
//            System.out.println("THIS IS LIST : "+list);
//        }
//
//        return list;
//    }
}
